<Project>
  <PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
    <!--
      Disable RAR from transitively discovering dependencies for references. This is required as we don't copy
      dependencies over into the output directory which means RAR can't resolve them.
    -->
    <_FindDependencies>false</_FindDependencies>
  </PropertyGroup>

  <!-- Project references shouldn't be copied to the output for reference, source, or generator projects. -->
  <ItemDefinitionGroup Condition="'$(IsSourceProject)' == 'true' or '$(IsReferenceAssemblyProject)' == 'true' or '$(IsGeneratorProject)' == 'true'">
    <ProjectReference>
      <Private>false</Private>
    </ProjectReference>
  </ItemDefinitionGroup>

  <ItemGroup Condition="'@(ProjectReference)' != ''">
    <_coreLibProjectReference Include="@(ProjectReference->WithMetadataValue('Identity', '$(CoreLibProject)'))" />
    <ProjectReference Update="@(_coreLibProjectReference)"
                      Private="false">
      <SetConfiguration Condition="'$(RuntimeFlavor)' == 'CoreCLR' and
                                   '$(Configuration)' != '$(CoreCLRConfiguration)'">Configuration=$(CoreCLRConfiguration)</SetConfiguration>
      <SetConfiguration Condition="'$(RuntimeFlavor)' == 'Mono' and
                                   '$(Configuration)' != '$(MonoConfiguration)'">Configuration=$(MonoConfiguration)</SetConfiguration>
    </ProjectReference>
    <!-- If a CoreLib ProjectReference is present, make all P2P assets non transitive. -->
    <ProjectReference Update="@(ProjectReference->WithMetadataValue('PrivateAssets', ''))"
                      PrivateAssets="all"
                      Condition="'$(IsSourceProject)' == 'true' and '@(_coreLibProjectReference)' != ''" />
  </ItemGroup>

  <!-- Make shared framework assemblies not app-local (non private). -->
  <Target Name="UpdateProjectReferencesWithPrivateAttribute"
          AfterTargets="AssignProjectConfiguration"
          BeforeTargets="PrepareProjectReferences"
          Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
                     ('$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true') and
                     '@(ProjectReferenceWithConfiguration)' != ''">
    <ItemGroup>
      <ProjectReferenceWithConfiguration PrivateAssets="all"
                                         Private="false"
                                         Condition="$(NetCoreAppLibrary.Contains('%(Filename);'))" />
    </ItemGroup>
  </Target>

  <Target Name="ReplaceCoreLibSrcWithRefAssemblyForCompilation"
          AfterTargets="FindReferenceAssembliesForReferences"
          Condition="'$(CompileUsingReferenceAssemblies)' != 'true' and '@(_coreLibProjectReference)' != ''">
    <ItemGroup>
      <_resolvedCoreLibProjectReference Include="@(_ResolvedProjectReferencePaths->WithMetadataValue('MSBuildSourceProjectFile','$(CoreLibProject)'))" />
      <ReferencePathWithRefAssemblies Remove="@(_resolvedCoreLibProjectReference)" />
      <ReferencePathWithRefAssemblies Include="@(_resolvedCoreLibProjectReference->Metadata('ReferenceAssembly'))" />
    </ItemGroup>
  </Target>
</Project>
